package thread;

// 匿名内部类 实现 创建Thread子类的方式

public class Demo3 {
    public static void main(String[] args) {
        Thread thread = new Thread() {
            // 创建Thread的子类，同时又实例化出对象
            @Override
            public void run() {
                while (true) {
                    System.out.println("hello thread!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        thread.start(); // 开始创建线程！

        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
